package com.third.customer.site.controller.resp;

import com.third.customer.model.tables.Area;
import com.third.customer.model.tables.Customer;
import com.third.customer.model.tables.CustomerGroup;
import com.third.customer.service.utils.TimeUtils;
import lombok.Data;

/**
 * Created by hehuaichun on 2020/6/27.
 */
@Data
public class CustomerResp {

    private String id;

    private String companyId;

    private String groupId;

    private String group;

    private String areaId;

    private String area;

    private String name;

    private String phone;

    private String address;

    private String remark;

    private String updatedAt;

    private String createdAt;

    public static CustomerResp convert(Customer customer, Area area, CustomerGroup group) {
        CustomerResp resp = new CustomerResp();
        resp.setId(String.valueOf(customer.getId()));
        resp.setCompanyId(String.valueOf(customer.getCompanyId()));
        resp.setGroupId(String.valueOf(customer.getGroupId()));
        resp.setAreaId(String.valueOf(customer.getAreaId()));
        resp.setName(customer.getName());
        resp.setAddress(customer.getAddress());
        resp.setPhone(customer.getPhone());
        resp.setRemark(customer.getRemark());
        if (customer.getUpdatedAt() != null) {
            resp.setUpdatedAt(TimeUtils.dateToString(customer.getUpdatedAt()));
        }
        if (customer.getCreatedAt() != null) {
            resp.setCreatedAt(TimeUtils.dateToString(customer.getCreatedAt()));
        }
        resp.setGroup(group.getName());
        resp.setArea(area.getCounty() + "-" + area.getCommunity());
        return resp;
    }
}
